package cn.jishiyu11.xeqb.utils

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.TextView

import cn.jishiyu11.xeqb.R
import cn.jishiyu11.xeqb.R.id.loading_text
import cn.jishiyu11.xeqb.view.CustomDialog

/**
 * Created by jsy_zj on 2017/11/8.
 */

class CustomDialogUtils {

    /**
     * 单例对象实例
     */
    private object CustomDialogUtilsHolder {
        internal val INSTANCE = CustomDialogUtils()
    }


    fun LoadingDialog(context: Context, displayContent: String): CustomDialog {
        val customDialog = CustomDialog(context, R.style.new_circle_progress)
        val contentView = LayoutInflater.from(context).inflate(R.layout.customdialog_laoding, null)
        customDialog.setContentView(contentView)
        customDialog.setCanceledOnTouchOutside(false)
        customDialog.setCancelable(false)
        contentView.findViewById<TextView>(R.id.loading_text).setText(displayContent)
        val dialogWindow = customDialog.window
        val lp = dialogWindow!!.attributes
        dialogWindow.setGravity(Gravity.CENTER)
        dialogWindow.attributes = lp
        return customDialog
    }

    fun TitleMessageButtonDialog(context: Context, title: String, msg: String): CustomDialog {
        val customDialog = CustomDialog(context, R.style.new_circle_progress)
        val contentView = LayoutInflater.from(context).inflate(R.layout.customdialog_laoding, null)
        customDialog.setContentView(contentView)
        customDialog.setCanceledOnTouchOutside(false)
        customDialog.setCancelable(false)

        val dialogWindow = customDialog.window
        val lp = dialogWindow!!.attributes
        dialogWindow.setGravity(Gravity.CENTER)
        dialogWindow.attributes = lp

        return customDialog
    }

    companion object {

        val instance: CustomDialogUtils
            get() = CustomDialogUtils.CustomDialogUtilsHolder.INSTANCE
    }

}
